package com.example.panda.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.panda.R;
import com.example.panda.mine.OnItemClickListener;
import com.example.panda.mine.RecyclerAdapter;
import com.example.panda.mine.list;
import com.example.panda.service.ChatActivity;

import java.util.ArrayList;
import java.util.List;


public class MeFragment extends Fragment {


    List<list> mListItem;
    RecyclerView mRrecyclerView;
    private OnItemClickListener onRecyclerviewItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 4){
                Intent intent1 = new Intent(getContext(), ChatActivity.class);
                startActivity(intent1);
            }

        }
    };

    int tp[] = {R.drawable.diary,R.drawable.attention,R.drawable.issue,R.drawable.collect,R.drawable.service};
    int tv[] = {R.string.diary,R.string.attention,R.string.issue,R.string.collect,R.string.service};
    int tp1[] = {R.drawable.more,R.drawable.more,R.drawable.more,R.drawable.more,R.drawable.more};

    public MeFragment() {
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {



        View view = inflater.inflate(R.layout.recycler_mian, container, false);

        mRrecyclerView = view.findViewById(R.id.recycler);

        mListItem = new ArrayList<>();
        Data();

        return view;
    }

    private void Data(){
        int kk[] = {View.GONE,View.GONE,View.GONE,View.VISIBLE,View.GONE,View.GONE,View.GONE,View.VISIBLE,View.GONE,View.GONE,View.GONE,View.VISIBLE};
        for (int i = 0; i < 6; i++) {
            try {

                list listitem = new list(tv[i],tp[i],tp1[i],kk[i]);
                mListItem.add(listitem);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        initRecyclerView(mListItem,getContext());

    }

    private void initRecyclerView(List list, Context context){
        RecyclerAdapter recyclerAdapter = new RecyclerAdapter(context,list,onRecyclerviewItemClickListener);
        mRrecyclerView.setLayoutManager(new GridLayoutManager(context,1));
        mRrecyclerView.setAdapter(recyclerAdapter);



    }
}
